﻿using log4net;
using log4net.Config;
using log4net.Repository;
using System;
using System.IO;

namespace ZCConsole
{
    public class LogHelper
    {
        private static ILog logger = null;
        public static void LogInfo(string logstr)
        {
            //Console.WriteLine(logstr);
            //if (InitLog4net())
            //    logger.Info(logstr);
        }

        //public static void LogInfo(string format, params object[] args)
        //{
        //    Console.WriteLine(format, args);
        //    if (InitLog4net())
        //        logger.InfoFormat(format, args);
        //}

        //public static void LogError(string logstr)
        //{
        //    Console.WriteLine(logstr);
        //    if (InitLog4net())
        //        logger.Error(logstr);
        //}

        public static void LogError(string info, Exception exception)
        {
            //Console.WriteLine(info, exception);
            //if (InitLog4net())
            //    logger.Error(info, exception);
        }

        private static object objlock = new object();//初始化log用的锁
        private static bool InitLog4net()
        {
            //if (logger != null)
            //    return true;
            //lock (objlock)
            //{
            //    if (logger == null)
            //    {
            //        ILoggerRepository repository = LogManager.CreateRepository("NETCoreRepository");
            //        XmlConfigurator.Configure(repository, new FileInfo("log4net.config"));
            //        logger = LogManager.GetLogger(repository.Name, "NETCorelog4net");
            //        return true;
            //    }
            //}
            //return false;
            return true;
        }
    }

}